package servlet;

import javax.servlet.*;
import java.io.IOException;

/**
 * @Author:石小俊
 * @Date:2022/12/12 10:07
 * @Version:1.0-SNAPSHOT
 * @Description:
 */
public class LifeServlet implements Servlet {

    private ServletConfig config;

    @Override
    public void init(ServletConfig config) throws ServletException {
        System.out.println("正在执行初始化方法");
//        String encoding = config.getInitParameter("encoding");
//        String name = config.getInitParameter("name");
//        System.out.println("encoding:"+encoding+",name:"+name);
        this.config = config;
    }

    @Override
    public ServletConfig getServletConfig() {
        return this.config;
    }

    public String getInitParameter(String name){
        return getServletConfig().getInitParameter(name);
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        System.out.println("LifeServlet.service");
//        String encoding = config.getInitParameter("encoding");
//        String name = config.getInitParameter("name");
        String encoding = getInitParameter("encoding");
        String name = getInitParameter("name");
        System.out.println("encoding:"+encoding+",name:"+name);
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {
        System.out.println("LifeServlet.destroy");
    }
}
